import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  ClassSerializerInterceptor,
  UseInterceptors,
  UseGuards,
} from '@nestjs/common';
import { TimeSlotsService } from './time-slots.service';
import { CreateTimeSlotDto } from './dto/create-time-slot.dto';
import { UpdateTimeSlotDto } from './dto/update-time-slot.dto';
import {
  ApiBody,
  ApiOperation,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { JwtGuard } from '../guards/jwt.guards';

@Controller('time-slots')
@UseInterceptors(ClassSerializerInterceptor)
@UseGuards(JwtGuard) // 校验token是否通过
@ApiTags('上课时间模块')
export class TimeSlotsController {
  constructor(private readonly timeSlotsService: TimeSlotsService) {}

  @Post()
  @ApiOperation({ summary: '上课时间创建' })
  @ApiBody({ type: CreateTimeSlotDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateTimeSlotDto,
  })
  create(@Body() createTimeSlotDto: CreateTimeSlotDto) {
    return this.timeSlotsService.create(createTimeSlotDto);
  }

  @Get()
  @ApiOperation({ summary: '时间列表' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: [CreateTimeSlotDto],
  })
  findAll() {
    return this.timeSlotsService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '详情' })
  @ApiQuery({ name: 'id', required: true, description: '时间段id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateTimeSlotDto,
  })
  findOne(@Param('id') id: number) {
    return this.timeSlotsService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '时间段更新' })
  @ApiQuery({ name: 'id', required: true, description: '时间段id' })
  @ApiBody({ type: UpdateTimeSlotDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateTimeSlotDto,
  })
  update(
    @Param('id') id: string,
    @Body() updateTimeSlotDto: UpdateTimeSlotDto,
  ) {
    return this.timeSlotsService.update(+id, updateTimeSlotDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '时间段删除' })
  @ApiQuery({ name: 'id', required: true, description: '时间段id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: Object,
  })
  remove(@Param('id') id: number) {
    return this.timeSlotsService.remove(id);
  }
}
